const obj = {
  getImage: ['images', 'png'],
  getAudio: ['audios', 'mp3'],
  getVideo: ['videos', 'mp4'],
}
const { VITE_OUT_DIR } = import.meta.env
const baseUrl = VITE_OUT_DIR ? '/' + VITE_OUT_DIR : ''

export const localFile = Object.entries(obj).reduce((p, c) => {
  const [key, [fileBasePath, defaultFileSuffix]] = c

  p[key] = path => {
    let url = path.includes('.') ? path : (path + '.' + defaultFileSuffix)
    url = `/static/${fileBasePath}/${url}`
    // #ifdef H5
    url = baseUrl + url
    // #endif
    return url
  }
  return p
}, <Record<keyof typeof obj, (path: string) => string>>{})